//
//  PortOut.m
//  CocoaSynth
//
//  Created by Jérémy Brault on 06/02/10.
//  Copyright 2010 None. All rights reserved.
//

#import "PortOut.h"
#import "ConnectorProtocol.h"
#import "ComputingStrategyProtocol.h"
#import "Module.h"
#import "PortIn.h"

@implementation PortOut

#pragma mark -
#pragma mark Memory Management

- (id)init 
{
	if (self = [super init]) {
		outputSample = nil;
		connector = nil;
		dispatcher = NO;
	}
	
	return self;
}

- (void)dealloc
{
	[outputSample release];
	outputSample = nil;
	
	[connector release];
	connector = nil;
	
	[super dealloc];
}

#pragma mark -
#pragma mark Accessors

@synthesize connector, computingStrategy, outputSample, dispatcher, module;

- (void)setConnector:(id<ConnectorProtocol>)aConnector
{
	if (connector != aConnector) {
		[connector release];
		connector = [aConnector retain];
	}
}

- (id<SampleProtocol>)outputSample
{
	if (dispatcher) {
		return [[module portIn] getSample];
	} else {
		return outputSample;
	}

}

#pragma mark - 
#pragma mark PortOutProtocol

- (BOOL)isConnected
{
	BOOL result = [connector isConnected];
	return result;
}

- (void)executeStrategy
{
	if (!dispatcher) {
		self.outputSample = [computingStrategy execute];
	}
}


@end
